package com.hopital5.zhangyz

import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import groovy.json.JsonOutput
import groovy.json.StringEscapeUtils
import org.junit.runner.RunWith
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.cache.annotation.EnableCaching
import org.springframework.test.context.ActiveProfiles
import org.springframework.test.context.junit4.SpringRunner

/**
 * Created by zhangyz on 16-4-25.
 */
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = [ApplicationTest.class],
        properties = [
                "xxxxxxx=xxxxxxx",
        ])
@ActiveProfiles("dev")
@EnableCaching
abstract class BaseTest {
    void jsonOutPut(Object o) {
        println StringEscapeUtils.unescapeJavaScript(JsonOutput.prettyPrint(new ObjectMapper().writeValueAsString(o)))
    }

    public <T> T jsonFileToObject(String filePath, Class<T> t) {
        return new ObjectMapper().disable(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS)
                .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
                .readValue(BaseTest.class.getResourceAsStream(filePath), t)
    }
}
